package sg.edu.nus.iss.stockex;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

public class TimestampPriceDataPoint implements Writable,
Comparable<TimestampPriceDataPoint> {
	private long longTradeDate;
	private double closePrice;
	private double openPrice;
	private double highPrice;
	private double lowPrice;
	private long volume;

	public void readFields(DataInput in) throws IOException {

		this.longTradeDate = in.readLong();
		this.closePrice = in.readDouble();
		this.openPrice = in.readDouble();
		this.highPrice = in.readDouble();
		this.lowPrice = in.readDouble();
		this.volume = in.readLong();
	}


	public static TimestampPriceDataPoint read(DataInput in) throws IOException {

		TimestampPriceDataPoint p = new TimestampPriceDataPoint();
		p.readFields(in);
		return p;

	}

	public String getDate() {

		return Util.formatDateFromLong(longTradeDate);

	}

	public void copy(TimestampPriceDataPoint source) {
		this.longTradeDate = source.longTradeDate;
		this.closePrice = source.closePrice;
		this.openPrice = source.openPrice;
		this.highPrice = source.highPrice;
		this.lowPrice = source.lowPrice;
		this.volume = source.volume;
	}

	@Override
	public void write(DataOutput out) throws IOException {

		out.writeLong(this.longTradeDate);
		out.writeDouble(this.closePrice);
		out.writeDouble(this.openPrice);
		out.writeDouble(this.highPrice);
		out.writeDouble(this.lowPrice);
		out.writeLong(this.volume);
	}

	@Override
	public int compareTo(TimestampPriceDataPoint other) {
		//System.out.println("$$$ " + getDate() + " / " + this.longTradeDate +" compare " + other.getDate() + " / " + other.longTradeDate);
		
		if (this.longTradeDate < other.longTradeDate) {
			return -1;
		} else if (this.longTradeDate > other.longTradeDate) {
			return 1;
		}
		return 0;
	}

	public long getLongTradeDate() {
		return longTradeDate;
	}

	public void setLongTradeDate(long longTradeDate) {
		this.longTradeDate = longTradeDate;
	}

	public double getClosePrice() {
		return closePrice;
	}

	public void setClosePrice(double closePrice) {
		this.closePrice = closePrice;
	}


	public double getOpenPrice() {
		return openPrice;
	}


	public void setOpenPrice(double openPrice) {
		this.openPrice = openPrice;
	}


	public double getHighPrice() {
		return highPrice;
	}


	public void setHighPrice(double highPrice) {
		this.highPrice = highPrice;
	}


	public double getLowPrice() {
		return lowPrice;
	}


	public void setLowPrice(double lowPrice) {
		this.lowPrice = lowPrice;
	}


	public long getVolume() {
		return volume;
	}


	public void setVolume(long volume) {
		this.volume = volume;
	}




}
